package com.tju.ocean_ecology_website.service.impl;

import com.tju.ocean_ecology_website.entity.DonationDetail;
import com.tju.ocean_ecology_website.dao.DonationDetailDao;
import com.tju.ocean_ecology_website.service.DonationDetailService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;

/**
 * 捐赠项目详情表(DonationDetail)表服务实现类
 *
 * @author shaolong
 * @since 2025-04-29 19:30:27
 */
@Service("donationDetailService")
public class DonationDetailServiceImpl implements DonationDetailService {
    @Resource
    private DonationDetailDao donationDetailDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public DonationDetail queryById(Long id) {
        return this.donationDetailDao.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param donationDetail 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<DonationDetail> queryByPage(DonationDetail donationDetail, PageRequest pageRequest) {
        long total = this.donationDetailDao.count(donationDetail);
        return new PageImpl<>(this.donationDetailDao.queryAllByLimit(donationDetail, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param donationDetail 实例对象
     * @return 实例对象
     */
    @Override
    public DonationDetail insert(DonationDetail donationDetail) {
        this.donationDetailDao.insert(donationDetail);
        return donationDetail;
    }

    /**
     * 修改数据
     *
     * @param donationDetail 实例对象
     * @return 实例对象
     */
    @Override
    public DonationDetail update(DonationDetail donationDetail) {
        this.donationDetailDao.update(donationDetail);
        return this.queryById(donationDetail.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Long id) {
        return this.donationDetailDao.deleteById(id) > 0;
    }
}
